Skip to content

Store credentials in Secrets Manager consistently + configurable KMS key - #5

Merged
timossileandro merged 4 commits into
mainfrom
feature/aurora-secrets-manager
Aug 24, 2026
Merged

Store credentials in Secrets Manager consistently + configurable KMS key#5
timossileandro merged 4 commits into
mainfrom
feature/aurora-secrets-manager

Conversation

@sebastiancorrea81

Copy link
Copy Markdown
Contributor

Summary

  • fix(aurora-postgres-db): app-level PostgreSQL credentials generated by db_setup are now also stored in Secrets Manager (nullplatform/aurora/<service_id>/app), matching how aurora-postgres-server already handles the master password. Previously they only lived in Terraform state and as a plain nullplatform service/link attribute. The new secret is destroyed alongside the app user on service delete, and its ARN is exposed as app_secret_arn on service/link attributes. The aurora-postgres-db IAM policy is widened from read-only GetSecretValue to full secret lifecycle management, scoped to the same nullplatform/aurora/* prefix.
  • feat(aurora-postgres-server): added an optional secret_kms_key_id parameter (Terraform variable + UI-exposed field) so each instance can use its own customer-managed KMS key to encrypt its master secret. Left unset, it keeps using the default aws/secretsmanager managed key. Unrelated to aws_kms_key.aurora, the existing customer-managed key used for cluster storage encryption.

Ports the same pair of changes already made in nullplatform/services-postgresql-rds (see nullplatform/services-postgresql-rds#8) to the Aurora variant of these services.

Test plan

  • terraform fmt/validate pass on aurora-postgres-server/deployment and aurora-postgres-db/db_setup (done locally)
  • Apply aurora-postgres-server requirements/deployment in a test account, confirm secret_kms_key_id left empty still creates the secret with the default AWS-managed key
  • Set secret_kms_key_id to a customer-managed key ARN, confirm the master secret is encrypted with it
  • Create an aurora-postgres-db service end-to-end, confirm aws_secretsmanager_secret nullplatform/aurora/<service_id>/app is created with the correct credentials
  • Delete the service, confirm the app secret is destroyed alongside the app user/password
  • Confirm link/unlink still work and app_secret_arn shows up in service and link attributes

🤖 Generated with Claude Code

sebas_correa and others added 2 commits August 18, 2026 16:30
…figurable

Add an optional secret_kms_key_id parameter (Terraform variable, service
attribute, and UI-exposed field in the service spec) so each
aurora-postgres-server instance can use its own customer-managed KMS key
to encrypt its master password secret. Left unset, the secret keeps
using the default aws/secretsmanager managed key, same as before.

This is unrelated to aws_kms_key.aurora, the existing customer-managed
key used for cluster storage encryption (AVD-AWS-0079) — that key stays
as-is.

Ports the same change already applied to rds-postgres-server in
nullplatform/services-postgresql-rds.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Previously the app user's credentials generated by db_setup lived only
in the Terraform state and as a plain nullplatform service/link
attribute — unlike aurora-postgres-server, which stores its master
password in Secrets Manager. Add an aws_secretsmanager_secret/_version
pair (nullplatform/aurora/<service_id>/app) alongside the existing
postgresql_role, following the same naming convention as the master
secret, and expose its ARN as app_secret_arn on both the service and
link attributes.

Wire the new region variable and aws provider into db_setup (needed to
create the secret), destroy the secret alongside the app user/password
on service delete, and widen the aurora-postgres-db IAM policy from
read-only GetSecretValue to full secret lifecycle management, scoped to
the same nullplatform/aurora/* prefix.

Ports the same fix already applied to rds-postgres-db in
nullplatform/services-postgresql-rds.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Comment thread aurora-postgres-db/db_setup/main.tf Fixed
Leandro Timossi and others added 2 commits August 24, 2026 17:20
…ed key

Trivy AVD-AWS-0098 flagged aws_secretsmanager_secret.app as explicitly
using the default key: with no kms_key_id, the app-level PostgreSQL
credentials are encrypted with the AWS-managed aws/secretsmanager key,
whose policy cannot be audited, restricted, or revoked by us.

Add a secret_kms_key_id variable (default null) and wire it through
build_db_setup_context, mirroring the change already applied to the
master secret in aurora-postgres-server. The value is inherited from the
auto-discovered server's secret_kms_key_id attribute rather than exposed
as a new per-database field, so a cluster's master secret and all of its
app secrets share one key and one revocation point — the encryption key
is an infrastructure-level choice that belongs on the server. Left unset
there, the app secret keeps using the managed key, same as before.

Also grant kms:Decrypt/kms:DescribeKey/kms:GenerateDataKey on the
AssumeRole policy, scoped by kms:ViaService to Secrets Manager. Secrets
Manager calls KMS on the role's behalf to wrap and unwrap the secret, so
without it a customer-managed key fails at CreateSecret with AccessDenied
on the key rather than on the secret.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
dfe1806 added the secret_kms_key_id parameter but not the IAM permissions
it needs, so setting it fails at apply: Secrets Manager calls KMS on the
role's behalf to wrap and unwrap the master secret, and the AssumeRole
policy had no kms:* actions at all. The parameter has therefore been
unusable since it shipped.

Grant kms:Decrypt/kms:DescribeKey/kms:GenerateDataKey. The key ARN is
operator-supplied and not knowable in requirements/, so Resource stays "*"
and the grant is constrained by kms:ViaService instead — the role can use
the key only for calls arriving through Secrets Manager, never to decrypt
anything else with it. Same statement as the one now in
aurora-postgres-db/specs/requirements/aws.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@timossileandro
timossileandro merged commit 23b7bee into main Aug 24, 2026
6 checks passed
@timossileandro
timossileandro deleted the feature/aurora-secrets-manager branch August 24, 2026 20:22
@timossileandro
timossileandro restored the feature/aurora-secrets-manager branch August 25, 2026 12:59
@timossileandro
timossileandro deleted the feature/aurora-secrets-manager branch August 25, 2026 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants